﻿using Furion.DatabaseAccessor;
using UpperComputer.Core;
using UpperComputer.EntityFramework.Core;
using YFurion.Locators;
using YFurion.Security;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class DatabaseAccessorServiceCollectionExtensions
    {
        public static IServiceCollection AddDatabaseAccessor(this IServiceCollection services, string masterConnectionString, string slaveConnectionString)
        {
            services.AddDatabaseAccessor(options =>
            {
                string mcs = Des3.Decrypt(masterConnectionString, UpperComputerCoreConst.HashPrefix);
                string scs = Des3.Decrypt(slaveConnectionString, UpperComputerCoreConst.HashPrefix);
                services.AddDbPool<MasterDbContext, MasterDbContextLocator>(DbProvider.SqlServer, connectionMetadata: mcs);
                services.AddDbPool<SlaveDbContext, SlaveDbContextLocator>(DbProvider.SqlServer, connectionMetadata: scs);
            }, "UpperComputer.Database.Migrations");
            return services;
        }
    }
}
